{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np #导入numpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "元数据地址为:2459027272064\n"
     ]
    }
   ],
   "source": [
    "data = [1,2,3]\n",
    "print(f\"元数据地址为:{id(data)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "arr1地址为:2459027678544\n",
      "数组数据为:[1 2 3]\n"
     ]
    }
   ],
   "source": [
    "arr = np.array(data)\n",
    "print(f\"arr1地址为:{id(arr)}\")\n",
    "print(f\"数组数据为:{arr}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------\n",
      "arr2地址为:2458922122000\n",
      "arr2数组数据为:[1 2 3]\n"
     ]
    }
   ],
   "source": [
    "print(\"-\" * 20)\n",
    "arr2 = np.array(arr)\n",
    "print(f\"arr2地址为:{id(arr2)}\")\n",
    "print(f\"arr2数组数据为:{arr2}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------\n",
      "arr3地址为:2459027678544\n",
      "arr3数组数据为:[1 2 3]\n"
     ]
    }
   ],
   "source": [
    "print(\"-\" * 20)\n",
    "arr3 = np.asarray(arr)\n",
    "print(f\"arr3地址为:{id(arr3)}\")\n",
    "print(f\"arr3数组数据为:{arr3}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 0.]]\n"
     ]
    }
   ],
   "source": [
    "#创建一个2*5 全为0的列表\n",
    "arr1 = np.zeros((2, 5))\n",
    "print(arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1. 1. 1. 1. 1.]\n",
      " [1. 1. 1. 1. 1.]]\n"
     ]
    }
   ],
   "source": [
    "#创建一个2*5 全为1的列表\n",
    "arr1 = np.ones((2, 5))\n",
    "print(arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[6.23042070e-307 1.33512376e-306 1.11261230e-306]\n",
      " [7.56577399e-307 9.34600963e-307 1.11262266e-307]]\n"
     ]
    }
   ],
   "source": [
    "arr1=np.empty((2,3))\n",
    "print(arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------\n",
      "[[0. 0. 0. 0. 0.]\n",
      " [0. 0. 0. 0. 0.]]\n"
     ]
    }
   ],
   "source": [
    "arr1 = np.zeros((2, 5))\n",
    "print(\"-\" * 20)\n",
    "print(arr1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------\n",
      "[[1. 1. 1. 1. 1.]\n",
      " [1. 1. 1. 1. 1.]]\n",
      "--------------------\n",
      "[[6.23042070e-307 1.33512376e-306 1.11261230e-306]\n",
      " [7.56577399e-307 9.34600963e-307 1.11262266e-307]]\n",
      "--------------------\n",
      "[[6.23042070e-307 1.33512376e-306 1.11261230e-306]\n",
      " [7.56577399e-307 9.34600963e-307 1.11262266e-307]]\n",
      "--------------------\n",
      "[[0. 0. 0.]\n",
      " [0. 0. 0.]]\n"
     ]
    }
   ],
   "source": [
    "arr2 = np.ones_like(arr1)# 创建和arr1形状相同的全1数组\n",
    "print(\"-\" * 20)\n",
    "print(arr2)\n",
    "arr3 = np.empty((2, 3))# 创建未初始化的数组\n",
    "print(\"-\" * 20)\n",
    "print(arr3)\n",
    "arr4 = np.empty_like(arr3)# 创建和arr3形状相同的未初始化数组\n",
    "print(\"-\" * 20)\n",
    "print(arr4)\n",
    "arr5 = np.zeros_like(arr4)# 创建和arr3形状相同的未初始化数组\n",
    "print(\"-\" * 20)\n",
    "print(arr5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[6 6 6]\n",
      " [6 6 6]]\n",
      "--------------------\n",
      "[[5 5 5]\n",
      " [5 5 5]]\n"
     ]
    }
   ],
   "source": [
    "#返回给定形状和类型的新数组，用指定的值填\n",
    "arr1 = np.full((2, 3), 6)\n",
    "print(arr1)\n",
    "print(\"-\" * 20)\n",
    "arr2 = np.full_like(arr1, 5)\n",
    "print(arr2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 2 4 6 8]\n",
      "[0 1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "#返回在给定范围内用均匀间隔的值填充的一维数组。\n",
    "arr1 = np.arange(0, 10, 2)\n",
    "print(arr1)\n",
    "\n",
    "arr1 = np.arange(0, 10, 1)\n",
    "print(arr1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 0.   2.5  5.   7.5 10. ]\n",
      "[0. 2. 4. 6. 8.]\n",
      "[ 4.          6.72717132 11.3137085  19.02731384 32.        ]\n"
     ]
    }
   ],
   "source": [
    "arr1 = np.linspace(start=0, stop=10, num=5)\n",
    "print(arr1)\n",
    "arr2 = np.linspace(start=0, stop=10, num=5, endpoint=False)# 设置\n",
    "print(arr2)\n",
    "\n",
    "arr3 = np.logspace(start=2, stop=5, num=5, base=2)\n",
    "print(arr3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0.09199401 0.80076735 0.4902705 ]\n",
      " [0.91655228 0.18477433 0.93186151]]\n",
      "[[5 1 1]\n",
      " [9 9 3]]\n",
      "[[5.55588975 4.63243795 3.15317224]\n",
      " [4.88523012 3.65614409 4.73464484]]\n",
      "[[ 1.85884911  0.86823511 -0.33851631]\n",
      " [ 1.90224329  0.23801763  0.9527084 ]]\n"
     ]
    }
   ],
   "source": [
    "arr1 = np.random.rand(2, 3)\n",
    "arr2 = np.random.randint(0, 10, (2, 3))\n",
    "arr3 = np.random.uniform(3, 6, (2, 3))\n",
    "arr4 = np.random.randn(2, 3)\n",
    "print(arr1)\n",
    "print(\"-\" * 20)\n",
    "print(arr2)\n",
    "print(\"-\" * 20)\n",
    "print(arr3)\n",
    "print(\"-\" * 20)\n",
    "print(arr4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.matrix(\"1 2; 3 4\")\n",
    "print(arr1)\n",
    "arr2 = np.matrix([[1, 2], [3, 4]])\n",
    "print(arr2)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
